<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>...扩展运算符</title>
	</head>
	<body>
		<script>
			//扩展运算符，将数组当做参数传递出去
			var str = [1,2,4];
			function add(arr){
				console.log(arr);
			}
			add(...str);
			//console.log(typeof str)
			function f(v, w, x, y, z) { }
			const args = [0, 1];
			f(-1, ...args, 2, ...[3]);
			//扩展符可以添加表达式
			/*const arr = [
			  ...(x > 0 ? ['a'] : []),
			  'b',
			];*///arr[a,b]
			//如果扩展运算符后面是一个空数组，则不产生任何效果。
			
			
			//数组的复制与合并
			[...[], 1]
			// [1]
			const a1 = [1, 2];
			// 写法一
			//const a2 = [...a1];
			// 写法二
			const [...a2] = a1;
			console.log(a2);
			const arr1 = [1,2,4];
			const arr2 = [3,5];
			const arr3 = [...arr1,...arr2];
			console.log(arr3);
		</script>
	</body>
</html>
